Imports DevExpress.XtraEditors.Repository

Public Class RoleExecute
    Dim vroleid As Integer
    Public Property Setroleid() As Integer
        Get
            Return vroleid
        End Get
        Set(ByVal value As Integer)
            vroleid = value
        End Set
    End Property

    Function getRoleExecute(ByVal roleid) As DataTable
        Dim dt As New DataTable
        If Utils.executeSP("proc_zroleexecute", New Object() {"get", roleid, Convert.DBNull, Convert.DBNull, Convert.DBNull, Convert.DBNull}, dt) Then
            If Not Utils.RowExist(dt) Then
                dt = Nothing
            End If
        End If
        Return dt
    End Function

    Private Sub RoleExecute_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Setroleid = 1
        Dim dt As New DataTable
        Dim dgv As New DataGridView
        dt = getRoleExecute(vroleid)
        dgv = DataGridView1
        If dt IsNot Nothing Then
            txtrole.Text = dt(0)("role")
            dgv.AutoGenerateColumns = False
            dgv.DataSource = dt
            For Each c As DataGridViewColumn In dgv.Columns
                c.DataPropertyName = c.Name
            Next

        End If
    End Sub


    Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
        Dim dt As New DataTable
        dt = DataGridView1.DataSource
        dt.AcceptChanges()
    End Sub

    Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
        Dim dt As New DataTable
        dt = DataGridView1.DataSource
        Utils.exec_SP("proc_zroleexecute", New Object() {"del", vroleid, Convert.DBNull, Convert.DBNull, Convert.DBNull, Convert.DBNull})
        For Each r As DataRow In dt.Rows
            Utils.exec_SP("proc_zroleexecute", New Object() {"set", vroleid, r("menuid"), r("to_insert"), r("to_update"), r("to_delete")})
        Next
        MsgBox("Execute Finish", MsgBoxStyle.Information)

    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        Me.Close()
    End Sub
End Class